package com.ems.controller;

import com.alibaba.fastjson.JSONObject;
import com.ems.exception.Result;
import com.ems.exception.ResultCode;
import com.ems.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @RequestMapping("/errorMsg")
    public Object errorMsg(){
        return Result.ok().data(adminService.errorMsg());
    }

    @RequestMapping(value = "/addstu", method = RequestMethod.POST)
    public Object addstu(Integer eid,String username){
        if(username != null && eid != null)
        {
            if(adminService.addstu(eid, username))
            {
                return Result.ok();
            }
            return Result.no();
        }
        return Result.state(ResultCode.NULLPOINTER);
    }

    @RequestMapping(value = "updateExam",method = RequestMethod.PUT)
    public Object updateExam(@RequestBody JSONObject json){
        if(json != null)
        {
            if (adminService.updateExam(json))
            {
                return Result.ok();
            }
            return Result.no();
        }
        return Result.state(ResultCode.NULLPOINTER);
    }
}
